import { setToken, http } from 'utils';
import { clearToken } from 'utils';
export const login = (mobile, code) => {
  return async (dispatch) => {
    const res = await http.post('/authorizations', {
      mobile,
      code,
    });
    // 注意：此处获取的是token不是refresh_token
    const { token } = res.data.data;
    setToken(token);
    dispatch({ type: 'login/token', payload: token });
    localStorage.setItem('pc-token', token);
  };
};
export const logout = () => {
  return (dispatch, getState) => {
    // 1、清楚token
    dispatch({
      type: 'login/clearToken',
    });
    // 清楚本地token
    clearToken();
    //2.清楚个人信息
    dispatch({
      type: 'user/clearInfo',
    });
  };
};
